<?php
	
	include_once(_PATH_HOME . '_lib/class.quickskin.php');
	include_once(_PATH_HOME . '_lib/class.db.php');
	include_once(_PATH_HOME . '_lib/class.agent.php');
	include_once(_PATH_HOME . '_lib/class.house.php');
	include_once(_PATH_HOME . '_lib/class.register.php');
	include_once(_PATH_HOME . '_lib/class.renthouse.php');
	include_once(_PATH_HOME . '_lib/class.sellhouse.php');
	include_once(_PATH_HOME . '_lib/class.message.php');
	include_once(_PATH_HOME . '_lib/class.collection.php');
	include_once(_PATH_HOME . '_lib/class.qgqzhouse.php');
	include_once(_PATH_HOME . '_lib/class.kuser.php');


	define("cookie_domain" , $_SERVER['HTTP_HOST']);
	
	//check login(0:unlogin 1:login)
	function checkLoginStatus(){
		global $myRegister;
		if(isset($_COOKIE["zz_prop"])&&isset($_COOKIE["zz_name"])&&isset($_COOKIE["zz_id"])&&isset($_COOKIE["zz_pwd"])){
			$result = $myRegister->checkLogin($_COOKIE["zz_name"],$_COOKIE["zz_pwd"],$_COOKIE["zz_prop"]);
			if($result == "fail"){
				$username = "";
				$userid = "";
				$prop = -1;
				$login = 0;
			}else{
				$myRegister->updateLoginTime($_COOKIE["zz_id"],$_COOKIE["zz_prop"]);
				$username = $_COOKIE["zz_name"];
				$userid = $_COOKIE["zz_id"];
				$prop=$_COOKIE["zz_prop"];
				$login = 1;
			}
		}else{
			$username = "";
			$userid = "";
			$prop = -1;
			$login = 0;
		}

		define("__login__",$login);
		define("__user_name__",$username);
		define("__user_id__",$userid);
		define("__user_prop__",$prop);
			
	}

	checkLoginStatus();
	
	function template_ini($tpl,$title=""){
		global $myMessage;
		$tpl->assign("logined" , __login__);
		$tpl->assign("login_user_name" , __user_name__);
		$tpl->assign("login_user_id" , __user_id__);
		$tpl->assign("login_user_prop" , __user_prop__);
		//$tpl->assign(array('logined'=>__login__,'login_user_name'=>__user_name__,'login_user_id'=>__user_id__ ,'login_user_prop'=>__user_prop__));
		global $myMessage;
	
		$msgnum = $myMessage->getMsgNum();
		$tpl->assign("msgnum" ,$msgnum);
	}


	function setCookies($arr){
		if($arr["autologin"]=="1"){
			$time = time()+60*60*24*30*6;
		}else{
			$time = time()+60*60*24;
		}
		
		/*setcookie("zz_prop", $arr["prop"] , $time , '/' ,  cookie_domain);  
		setcookie("zz_name", $arr["name"] , $time , '/' ,  cookie_domain);  
		setcookie("zz_id", $arr["id"] , $time, '/' ,  cookie_domain);   
		setcookie("zz_pwd", $arr["pwd"] , $time , '/' ,  cookie_domain);*/
		
		setcookie("zz_prop", $arr["prop"] , $time);  
		setcookie("zz_name", $arr["name"] , $time );  
		setcookie("zz_id", $arr["id"] , $time);   
		setcookie("zz_pwd", $arr["pwd"] , $time);
		
	}
	
	function setCookiebyId($key , $val){
		$time = time()+60*60*24*30;
		setcookie($key, $val , $time , '/' ,  cookie_domain);  
	}

	function isLogin($prop=-1){
		if($prop!=-1&&__user_prop!=$prop){
			return false;
		}
		if(__login__==0||__user_name__==""||__user_id__==""){
			return false;
		}
		return true;
	}

	function clearCookies(){
		/*setcookie("zz_prop", "" , time()-1 , '/' ,  cookie_domain);  
		setcookie("zz_name", "" ,  time()-1 , '/' ,  cookie_domain);  
		setcookie("zz_id", "" , time()-1 , '/' ,  cookie_domain);  
		setcookie("zz_pwd", "" ,  time()-1 , '/' ,  cookie_domain);  */
		setcookie("zz_prop", "" , time()-1);  
		setcookie("zz_name", "" ,  time()-1);  
		setcookie("zz_id", "" , time()-1);  
		setcookie("zz_pwd", "" ,  time()-1); 
	}

	
	
	

	define("__index_agent_num__" , 66);
	define("__index_kfs_num__" , 66);
	define("__index_goldagent_num__" , 6);
	define("__index_shouse_num__" , 30);
	define("__index_rhouse_num__" , 30);
	
	define("__index_new_num__" , 7 );
	
	define("__search_shouse_num__" , 30);
	define("__search_rhouse_num__" , 30);
	define("__search_qhouse_num__" , 30);
	define("__search_agent_num__" , 66);
	define("__search_kfs_num__" , 20);
	define("__search_map_num__" , 10);
	
	define("__admin_qghouse_num__" , 20);
	define("__admin_qzhouse_num__" , 20);
	define("__admin_shhouse_num__" , 20);
	define("__admin_rhhouse_num__" , 20);
	
	define("__upload_score__" , 10);
	define("__editinfo_score__" , 50);

?>